<?php

use think\migration\Migrator;
use think\migration\db\Column;

class DeliveryLog extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('delivery_log', ['engine' => 'InnoDB', 'comment' => '送货记录', 'signed' => false]);
        $table->addColumn('company_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '公司id', 'signed' => false])
            ->addColumn('store_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '门店id', 'signed' => false])
            ->addColumn('driver_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '司机id', 'signed' => false])
            ->addColumn('lon', 'string', ['limit' => 30, 'default' => '', 'comment' => '经度', 'collation' => 'utf8mb4_general_ci'])
            ->addColumn('lat', 'string', ['limit' => 30, 'default' => '', 'comment' => '纬度', 'collation' => 'utf8mb4_general_ci'])
            ->addColumn('status', 'integer', ['limit' => 10, 'default' => 1, 'comment' => '配送状态，1正常 2异常', 'signed' => false])
            ->addColumn('company_order_id', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '子订单id', 'signed' => false])
            ->addColumn('company_order_pid', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '主订单id', 'signed' => false])
            ->addColumn('money', 'decimal', ['default' => 0.00, 'comment' => '金额', 'signed' => false])
            ->addColumn('image', 'string', ['limit' => 255, 'default' => '', 'comment' => '收款凭证', 'collation' => 'utf8mb4_general_ci'])
            ->addColumn('remark', 'string', ['limit' => 255, 'default' => '', 'comment' => '备注', 'collation' => 'utf8mb4_general_ci'])
            ->addColumn('create_time', 'integer', ['limit' => 10, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit' => 10, 'default' => null, 'comment' => '更新时间'])
            ->addColumn('delete_time', 'integer', ['limit' => 10, 'default' => null, 'comment' => '删除时间'])
            ->addIndex('company_id', ['name' => 'idx_company_id'])
            ->addIndex('store_id', ['name' => 'idx_store_id'])
            ->addIndex('driver_id', ['name' => 'idx_driver_id'])
            ->addIndex('status', ['name' => 'idx_status'])
            ->addIndex('company_order_id', ['name' => 'idx_company_order_id'])
            ->addIndex('company_order_pid', ['name' => 'idx_company_order_pid'])
            ->create();
    }
}
